<!DOCTYPE html>
<html >

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Python3学习教程</title>
  <meta name="description" content="Python3学习教程">
  <meta name="generator" content="bookdown 0.5 and GitBook 2.6.7">

  <meta property="og:title" content="Python3学习教程" />
  <meta property="og:type" content="book" />
  
  
  
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="Python3学习教程" />
  
  
  

<meta name="author" content="易生信培训团队">
<meta name="author" content="联系我们: train@ehbio.com">
<meta name="author" content="抱歉，转成PDF后部分格式问题还未解决，会继续更新调整">


<meta name="date" content="2018-05-09">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  
  
<link rel="prev" href="py3-pandas-ct.html">
<link rel="next" href="Py3-test.html">
<script src="libs/jquery-2.2.3/jquery.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />









<style type="text/css">
div.sourceCode { overflow-x: auto; }
table.sourceCode, tr.sourceCode, td.lineNumbers, td.sourceCode {
  margin: 0; padding: 0; vertical-align: baseline; border: none; }
table.sourceCode { width: 100%; line-height: 100%; }
td.lineNumbers { text-align: right; padding-right: 4px; padding-left: 4px; color: #aaaaaa; border-right: 1px solid #aaaaaa; }
td.sourceCode { padding-left: 5px; }
code > span.kw { color: #007020; font-weight: bold; } /* Keyword */
code > span.dt { color: #902000; } /* DataType */
code > span.dv { color: #40a070; } /* DecVal */
code > span.bn { color: #40a070; } /* BaseN */
code > span.fl { color: #40a070; } /* Float */
code > span.ch { color: #4070a0; } /* Char */
code > span.st { color: #4070a0; } /* String */
code > span.co { color: #60a0b0; font-style: italic; } /* Comment */
code > span.ot { color: #007020; } /* Other */
code > span.al { color: #ff0000; font-weight: bold; } /* Alert */
code > span.fu { color: #06287e; } /* Function */
code > span.er { color: #ff0000; font-weight: bold; } /* Error */
code > span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
code > span.cn { color: #880000; } /* Constant */
code > span.sc { color: #4070a0; } /* SpecialChar */
code > span.vs { color: #4070a0; } /* VerbatimString */
code > span.ss { color: #bb6688; } /* SpecialString */
code > span.im { } /* Import */
code > span.va { color: #19177c; } /* Variable */
code > span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code > span.op { color: #666666; } /* Operator */
code > span.bu { } /* BuiltIn */
code > span.ex { } /* Extension */
code > span.pp { color: #bc7a00; } /* Preprocessor */
code > span.at { color: #7d9029; } /* Attribute */
code > span.do { color: #ba2121; font-style: italic; } /* Documentation */
code > span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code > span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
</style>

<link rel="stylesheet" href="style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="http://www.ehbio.com"><img src="http://www.ehbio.com/logos/ehbio_gitbook_logo.png" width="95%"></a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>EHBIO Gene Technology</a></li>
<li class="chapter" data-level="1" data-path="pythonbasic.html"><a href="pythonbasic.html"><i class="fa fa-check"></i><b>1</b> Python基础</a><ul>
<li class="chapter" data-level="1.1" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.1"><i class="fa fa-check"></i><b>1.1</b> 交互模式下表达式</a></li>
<li class="chapter" data-level="1.2" data-path="pythonbasic.html"><a href="pythonbasic.html#pythonintfloatstr"><i class="fa fa-check"></i><b>1.2</b> Python中的数据类型：整数（int）、浮点（float）和字符串（str）</a></li>
<li class="chapter" data-level="1.3" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.3"><i class="fa fa-check"></i><b>1.3</b> 字符串的连接和复制</a></li>
<li class="chapter" data-level="1.4" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.4"><i class="fa fa-check"></i><b>1.4</b> 变量</a></li>
<li class="chapter" data-level="1.5" data-path="pythonbasic.html"><a href="pythonbasic.html#helloworld.py"><i class="fa fa-check"></i><b>1.5</b> 第一小程序HelloWorld.py</a></li>
<li class="chapter" data-level="1.6" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.6"><i class="fa fa-check"></i><b>1.6</b> 逻辑和比较操作</a><ul>
<li class="chapter" data-level="1.6.1" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.6.1"><i class="fa fa-check"></i><b>1.6.1</b> 布尔逻辑值</a></li>
<li class="chapter" data-level="1.6.2" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.6.2"><i class="fa fa-check"></i><b>1.6.2</b> 比较操作符</a></li>
<li class="chapter" data-level="1.6.3" data-path="pythonbasic.html"><a href="pythonbasic.html#-and-or-not"><i class="fa fa-check"></i><b>1.6.3</b> 布尔操作符 and or not</a></li>
<li class="chapter" data-level="1.6.4" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.6.4"><i class="fa fa-check"></i><b>1.6.4</b> 布尔操作和比较操作符</a></li>
</ul></li>
<li class="chapter" data-level="1.7" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.7"><i class="fa fa-check"></i><b>1.7</b> 控制流</a><ul>
<li class="chapter" data-level="1.7.1" data-path="pythonbasic.html"><a href="pythonbasic.html#if-"><i class="fa fa-check"></i><b>1.7.1</b> if 语句</a></li>
<li class="chapter" data-level="1.7.2" data-path="pythonbasic.html"><a href="pythonbasic.html#elif-"><i class="fa fa-check"></i><b>1.7.2</b> elif 否则如果</a></li>
<li class="chapter" data-level="1.7.3" data-path="pythonbasic.html"><a href="pythonbasic.html#while"><i class="fa fa-check"></i><b>1.7.3</b> while循环</a></li>
<li class="chapter" data-level="1.7.4" data-path="pythonbasic.html"><a href="pythonbasic.html#breakcontinue"><i class="fa fa-check"></i><b>1.7.4</b> break和continue</a></li>
<li class="chapter" data-level="1.7.5" data-path="pythonbasic.html"><a href="pythonbasic.html#for--range"><i class="fa fa-check"></i><b>1.7.5</b> for 和 range（）函数</a></li>
<li class="chapter" data-level="1.7.6" data-path="pythonbasic.html"><a href="pythonbasic.html#range"><i class="fa fa-check"></i><b>1.7.6</b> range()函数（开始，停止，步长）</a></li>
</ul></li>
<li class="chapter" data-level="1.8" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.8"><i class="fa fa-check"></i><b>1.8</b> 导入模块</a></li>
<li class="chapter" data-level="1.9" data-path="pythonbasic.html"><a href="pythonbasic.html#-"><i class="fa fa-check"></i><b>1.9</b> 函数： 内置函数、自定义函数</a><ul>
<li class="chapter" data-level="1.9.1" data-path="pythonbasic.html"><a href="pythonbasic.html#printlen-input-intstr"><i class="fa fa-check"></i><b>1.9.1</b> 函数print（），len （）,input （），int（），str（）均为内置函数</a></li>
</ul></li>
<li class="chapter" data-level="1.10" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.10"><i class="fa fa-check"></i><b>1.10</b> 局部和全局作用域</a></li>
<li class="chapter" data-level="1.11" data-path="pythonbasic.html"><a href="pythonbasic.html#global"><i class="fa fa-check"></i><b>1.11</b> 声明为全局变量global</a></li>
<li class="chapter" data-level="1.12" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.12"><i class="fa fa-check"></i><b>1.12</b> 异常的处理</a></li>
<li class="chapter" data-level="1.13" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.13"><i class="fa fa-check"></i><b>1.13</b> 列表</a></li>
<li class="chapter" data-level="1.14" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.14"><i class="fa fa-check"></i><b>1.14</b> 字符串和元组</a></li>
<li class="chapter" data-level="1.15" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.15"><i class="fa fa-check"></i><b>1.15</b> 引用</a></li>
<li class="chapter" data-level="1.16" data-path="pythonbasic.html"><a href="pythonbasic.html#--"><i class="fa fa-check"></i><b>1.16</b> 字典 键：值 对</a></li>
<li class="chapter" data-level="1.17" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.17"><i class="fa fa-check"></i><b>1.17</b> 字典与列表</a><ul>
<li class="chapter" data-level="1.17.1" data-path="pythonbasic.html"><a href="pythonbasic.html#keysvaluesitems"><i class="fa fa-check"></i><b>1.17.1</b> keys()、values（）和items( )</a></li>
</ul></li>
<li class="chapter" data-level="1.18" data-path="pythonbasic.html"><a href="pythonbasic.html#section-1.18"><i class="fa fa-check"></i><b>1.18</b> 字符串操作</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="py3-ct.html"><a href="py3-ct.html"><i class="fa fa-check"></i><b>2</b> Python 教程</a><ul>
<li class="chapter" data-level="2.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.1"><i class="fa fa-check"></i><b>2.1</b> 背景介绍</a><ul>
<li class="chapter" data-level="2.1.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.1.1"><i class="fa fa-check"></i><b>2.1.1</b> 编程开篇</a></li>
<li class="chapter" data-level="2.1.2" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.2</b> 为什么学习Python</a></li>
<li class="chapter" data-level="2.1.3" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.3</b> Python常用包</a></li>
<li class="chapter" data-level="2.1.4" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.4</b> 怎么学习Python</a></li>
<li class="chapter" data-level="2.1.5" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.5</b> Python学习的几个阶段</a></li>
<li class="chapter" data-level="2.1.6" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.6</b> 如何安装Python</a></li>
<li class="chapter" data-level="2.1.7" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.7</b> 如何运行Python命令和脚本</a></li>
<li class="chapter" data-level="2.1.8" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.1.8</b> 使用什么编辑器写Python脚本</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.2</b> Python程序事例</a></li>
<li class="chapter" data-level="2.3" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.3</b> Python语法</a><ul>
<li class="chapter" data-level="2.3.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.3.1"><i class="fa fa-check"></i><b>2.3.1</b> 层级缩进</a></li>
<li class="chapter" data-level="2.3.2" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.3.2</b> Python作为计算器的使用</a></li>
<li class="chapter" data-level="2.3.3" data-path="py3-ct.html"><a href="py3-ct.html#section-2.3.3"><i class="fa fa-check"></i><b>2.3.3</b> 变量、数据结构、流程控制</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="py3-ct.html"><a href="py3-ct.html#section-2.4"><i class="fa fa-check"></i><b>2.4</b> 输入输出</a><ul>
<li class="chapter" data-level="2.4.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.4.1"><i class="fa fa-check"></i><b>2.4.1</b> 交互式输入输出</a></li>
<li class="chapter" data-level="2.4.2" data-path="py3-ct.html"><a href="py3-ct.html#section-2.4.2"><i class="fa fa-check"></i><b>2.4.2</b> 文件读写</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="py3-ct.html"><a href="py3-ct.html#section-2.5"><i class="fa fa-check"></i><b>2.5</b> 实战练习（一）</a><ul>
<li class="chapter" data-level="2.5.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.5.1"><i class="fa fa-check"></i><b>2.5.1</b> 背景知识</a></li>
<li class="chapter" data-level="2.5.2" data-path="pythonbasic.html"><a href="pythonbasic.html#-"><i class="fa fa-check"></i><b>2.5.2</b> 作业 (一)</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="py3-ct.html"><a href="py3-ct.html#section-2.6"><i class="fa fa-check"></i><b>2.6</b> 函数操作</a><ul>
<li class="chapter" data-level="2.6.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.6.1"><i class="fa fa-check"></i><b>2.6.1</b> 作业（二）</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="py3-ct.html"><a href="py3-ct.html#section-2.7"><i class="fa fa-check"></i><b>2.7</b> 模块</a></li>
<li class="chapter" data-level="2.8" data-path="py3-ct.html"><a href="py3-ct.html#section-2.8"><i class="fa fa-check"></i><b>2.8</b> 命令行参数</a><ul>
<li class="chapter" data-level="2.8.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.8.1"><i class="fa fa-check"></i><b>2.8.1</b> 作业（三）</a></li>
</ul></li>
<li class="chapter" data-level="2.9" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.9</b> 更多Python内容</a><ul>
<li class="chapter" data-level="2.9.1" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.1"><i class="fa fa-check"></i><b>2.9.1</b> <strong>单语句块</strong></a></li>
<li class="chapter" data-level="2.9.2" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.2"><i class="fa fa-check"></i><b>2.9.2</b> 列表解析</a></li>
<li class="chapter" data-level="2.9.3" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.3"><i class="fa fa-check"></i><b>2.9.3</b> 字典解析</a></li>
<li class="chapter" data-level="2.9.4" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.4"><i class="fa fa-check"></i><b>2.9.4</b> 断言</a></li>
<li class="chapter" data-level="2.9.5" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.5"><i class="fa fa-check"></i><b>2.9.5</b> 更多字符串方法</a></li>
<li class="chapter" data-level="2.9.6" data-path="py3-ct.html"><a href="py3-ct.html#lambda-map-filer-reduce-"><i class="fa fa-check"></i><b>2.9.6</b> lambda, map, filer, reduce (保留节目)</a></li>
<li class="chapter" data-level="2.9.7" data-path="py3-ct.html"><a href="py3-ct.html#exec-eval-python-"><i class="fa fa-check"></i><b>2.9.7</b> <strong>exec, eval (执行字符串python语句, 保留节目)</strong></a></li>
<li class="chapter" data-level="2.9.8" data-path="py3-ct.html"><a href="py3-ct.html#section-2.9.8"><i class="fa fa-check"></i><b>2.9.8</b> 正则表达式</a></li>
</ul></li>
<li class="chapter" data-level="2.10" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>2.10</b> Python画图</a></li>
<li class="chapter" data-level="2.11" data-path="py3-ct.html"><a href="py3-ct.html#reference"><i class="fa fa-check"></i><b>2.11</b> Reference</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html"><i class="fa fa-check"></i><b>3</b> Python作图</a><ul>
<li class="chapter" data-level="3.1" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#section-3.1"><i class="fa fa-check"></i><b>3.1</b> 绘图基础</a><ul>
<li class="chapter" data-level="3.1.1" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#figuresubplot-1"><i class="fa fa-check"></i><b>3.1.1</b> Figure和Subplot</a></li>
<li class="chapter" data-level="3.1.2" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#subplot-1"><i class="fa fa-check"></i><b>3.1.2</b> 调整subplot周围间距</a></li>
<li class="chapter" data-level="3.1.3" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#--1"><i class="fa fa-check"></i><b>3.1.3</b> 颜色 标记和线型</a></li>
<li class="chapter" data-level="3.1.4" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.1.4</b> 刻度、标签和图例</a></li>
<li class="chapter" data-level="3.1.5" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#legend-1"><i class="fa fa-check"></i><b>3.1.5</b> 添加图例legend</a></li>
<li class="chapter" data-level="3.1.6" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.1.6</b> 注解</a></li>
<li class="chapter" data-level="3.1.7" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.1.7</b> 图片保存</a></li>
</ul></li>
<li class="chapter" data-level="3.2" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#section-3.2"><i class="fa fa-check"></i><b>3.2</b> 绘图实例</a><ul>
<li class="chapter" data-level="3.2.1" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.1</b> 绘制散点图</a></li>
<li class="chapter" data-level="3.2.2" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.2</b> 折线图</a></li>
<li class="chapter" data-level="3.2.3" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.3</b> 直方图</a></li>
<li class="chapter" data-level="3.2.4" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.4</b> 直条图</a></li>
<li class="chapter" data-level="3.2.5" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.5</b> 箱线图</a></li>
<li class="chapter" data-level="3.2.6" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>3.2.6</b> 饼图</a></li>
<li class="chapter" data-level="3.2.7" data-path="Python-plot-WXN.html"><a href="Python-plot-WXN.html#section-3.2.7"><i class="fa fa-check"></i><b>3.2.7</b> 绘制基因矩阵的热图</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="Py3-pratcise-ct.html"><a href="Py3-pratcise-ct.html"><i class="fa fa-check"></i><b>4</b> Python实战</a><ul>
<li class="chapter" data-level="4.1" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>4.1</b> Python实战</a><ul>
<li class="chapter" data-level="4.1.1" data-path="Py3-pratcise-ct.html"><a href="Py3-pratcise-ct.html#id"><i class="fa fa-check"></i><b>4.1.1</b> ID转换</a></li>
<li class="chapter" data-level="4.1.2" data-path="Py3-pratcise-ct.html"><a href="Py3-pratcise-ct.html#section-4.1.2"><i class="fa fa-check"></i><b>4.1.2</b> 每条染色体基因数目统计</a></li>
<li class="chapter" data-level="4.1.3" data-path="Py3-pratcise-ct.html"><a href="Py3-pratcise-ct.html#section-4.1.3"><i class="fa fa-check"></i><b>4.1.3</b> 所有外显子总长度统计</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="py3-ct.html"><a href="py3-ct.html#python"><i class="fa fa-check"></i><b>4.2</b> Python小技巧</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html"><i class="fa fa-check"></i><b>5</b> Pandas 学习教程</a><ul>
<li class="chapter" data-level="5.1" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#what-is-pandas"><i class="fa fa-check"></i><b>5.1</b> What is pandas</a></li>
<li class="chapter" data-level="5.2" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#pandas"><i class="fa fa-check"></i><b>5.2</b> Pandas读取文件</a><ul>
<li class="chapter" data-level="5.2.1" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.1"><i class="fa fa-check"></i><b>5.2.1</b> 获取目标文件</a></li>
<li class="chapter" data-level="5.2.2" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.2"><i class="fa fa-check"></i><b>5.2.2</b> 查看目标文件内容和格式</a></li>
<li class="chapter" data-level="5.2.3" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.3"><i class="fa fa-check"></i><b>5.2.3</b> 读取两列文件</a></li>
<li class="chapter" data-level="5.2.4" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.4"><i class="fa fa-check"></i><b>5.2.4</b> 数据表的索引</a></li>
<li class="chapter" data-level="5.2.5" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.5"><i class="fa fa-check"></i><b>5.2.5</b> 读取多列文件</a></li>
<li class="chapter" data-level="5.2.6" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.6"><i class="fa fa-check"></i><b>5.2.6</b> 选取多列数据</a></li>
<li class="chapter" data-level="5.2.7" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.7"><i class="fa fa-check"></i><b>5.2.7</b> 重命名列名字</a></li>
<li class="chapter" data-level="5.2.8" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.8"><i class="fa fa-check"></i><b>5.2.8</b> 合并矩阵</a></li>
<li class="chapter" data-level="5.2.9" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.2.9"><i class="fa fa-check"></i><b>5.2.9</b> 矩阵数据提取</a></li>
<li class="chapter" data-level="5.2.10" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#meta-data"><i class="fa fa-check"></i><b>5.2.10</b> 读取META data文件</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#pandas"><i class="fa fa-check"></i><b>5.3</b> Pandas写入文件</a><ul>
<li class="chapter" data-level="5.3.1" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#section-5.3.1"><i class="fa fa-check"></i><b>5.3.1</b> 写入文本文件</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#pandas"><i class="fa fa-check"></i><b>5.4</b> PANDAS矩阵的小应用</a></li>
<li class="chapter" data-level="5.5" data-path="py3-pandas-ct.html"><a href="py3-pandas-ct.html#seaborn"><i class="fa fa-check"></i><b>5.5</b> Seaborn绘图</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="numpy-scipy.html"><a href="numpy-scipy.html"><i class="fa fa-check"></i><b>6</b> Python科学计算</a><ul>
<li class="chapter" data-level="6.1" data-path="numpy-scipy.html"><a href="numpy-scipy.html#numpy"><i class="fa fa-check"></i><b>6.1</b> NumPy</a><ul>
<li class="chapter" data-level="6.1.1" data-path="numpy-scipy.html"><a href="numpy-scipy.html#numpy"><i class="fa fa-check"></i><b>6.1.1</b> NumPy数组</a></li>
<li class="chapter" data-level="6.1.2" data-path="numpy-scipy.html"><a href="numpy-scipy.html#numpy"><i class="fa fa-check"></i><b>6.1.2</b> 布尔语句和NumPy数组</a></li>
<li class="chapter" data-level="6.1.3" data-path="numpy-scipy.html"><a href="numpy-scipy.html#numpy"><i class="fa fa-check"></i><b>6.1.3</b> NumPy读写文件</a></li>
<li class="chapter" data-level="6.1.4" data-path="numpy-scipy.html"><a href="numpy-scipy.html#numpymath"><i class="fa fa-check"></i><b>6.1.4</b> NumPy的Math模块</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="numpy-scipy.html"><a href="numpy-scipy.html#scipy"><i class="fa fa-check"></i><b>6.2</b> SciPy</a><ul>
<li class="chapter" data-level="6.2.1" data-path="numpy-scipy.html"><a href="numpy-scipy.html#section-6.2.1"><i class="fa fa-check"></i><b>6.2.1</b> 最优化和最小化</a></li>
<li class="chapter" data-level="6.2.2" data-path="numpy-scipy.html"><a href="numpy-scipy.html#section-6.2.2"><i class="fa fa-check"></i><b>6.2.2</b> 插值</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="7" data-path="Py3-test.html"><a href="Py3-test.html"><i class="fa fa-check"></i><b>7</b> 易生信Python培训练习和考核题目</a></li>
<li class="chapter" data-level="8" data-path="references.html"><a href="references.html"><i class="fa fa-check"></i><b>8</b> 生信教程文章集锦</a><ul>
<li class="chapter" data-level="8.1" data-path="references.html"><a href="references.html#section-8.1"><i class="fa fa-check"></i><b>8.1</b> 生信宝典</a><ul>
<li class="chapter" data-level="8.1.1" data-path="references.html"><a href="references.html#section-8.1.1"><i class="fa fa-check"></i><b>8.1.1</b> 系列教程</a></li>
<li class="chapter" data-level="8.1.2" data-path="references.html"><a href="references.html#ngs"><i class="fa fa-check"></i><b>8.1.2</b> NGS分析工具评估</a></li>
<li class="chapter" data-level="8.1.3" data-path="references.html"><a href="references.html#section-8.1.3"><i class="fa fa-check"></i><b>8.1.3</b> 宏基因组教程</a></li>
<li class="chapter" data-level="8.1.4" data-path="references.html"><a href="references.html#section-8.1.4"><i class="fa fa-check"></i><b>8.1.4</b> 系列宣传</a></li>
<li class="chapter" data-level="8.1.5" data-path="references.html"><a href="references.html#section-8.1.5"><i class="fa fa-check"></i><b>8.1.5</b> 生信生物知识</a></li>
<li class="chapter" data-level="8.1.6" data-path="references.html"><a href="references.html#section-8.1.6"><i class="fa fa-check"></i><b>8.1.6</b> 文献精读</a></li>
<li class="chapter" data-level="8.1.7" data-path="references.html"><a href="references.html#linux"><i class="fa fa-check"></i><b>8.1.7</b> Linux</a></li>
<li class="chapter" data-level="8.1.8" data-path="references.html"><a href="references.html#circos"><i class="fa fa-check"></i><b>8.1.8</b> CIRCOS系列</a></li>
<li class="chapter" data-level="8.1.9" data-path="references.html"><a href="references.html#r"><i class="fa fa-check"></i><b>8.1.9</b> R统计和作图</a></li>
<li class="chapter" data-level="8.1.10" data-path="references.html"><a href="references.html#section-8.1.10"><i class="fa fa-check"></i><b>8.1.10</b> 扩增子三步曲</a></li>
<li class="chapter" data-level="8.1.11" data-path="references.html"><a href="references.html#section-8.1.11"><i class="fa fa-check"></i><b>8.1.11</b> 宏基因组分析专题</a></li>
<li class="chapter" data-level="8.1.12" data-path="references.html"><a href="references.html#ngs"><i class="fa fa-check"></i><b>8.1.12</b> NGS基础</a></li>
<li class="chapter" data-level="8.1.13" data-path="references.html"><a href="references.html#section-8.1.13"><i class="fa fa-check"></i><b>8.1.13</b> 癌症数据库</a></li>
<li class="chapter" data-level="8.1.14" data-path="references.html"><a href="references.html#python-1"><i class="fa fa-check"></i><b>8.1.14</b> Python</a></li>
<li class="chapter" data-level="8.1.15" data-path="references.html"><a href="references.html#ngs"><i class="fa fa-check"></i><b>8.1.15</b> NGS软件</a></li>
<li class="chapter" data-level="8.1.16" data-path="references.html"><a href="references.html#cytoscape"><i class="fa fa-check"></i><b>8.1.16</b> Cytoscape网络图</a></li>
<li class="chapter" data-level="8.1.17" data-path="references.html"><a href="references.html#section-8.1.17"><i class="fa fa-check"></i><b>8.1.17</b> 分子对接</a></li>
<li class="chapter" data-level="8.1.18" data-path="references.html"><a href="references.html#section-8.1.18"><i class="fa fa-check"></i><b>8.1.18</b> 生信宝典之傻瓜式</a></li>
<li class="chapter" data-level="8.1.19" data-path="references.html"><a href="references.html#section-8.1.19"><i class="fa fa-check"></i><b>8.1.19</b> 生信人写程序</a></li>
<li class="chapter" data-level="8.1.20" data-path="references.html"><a href="references.html#section-8.1.20"><i class="fa fa-check"></i><b>8.1.20</b> 小技巧系列</a></li>
<li class="chapter" data-level="8.1.21" data-path="references.html"><a href="references.html#section-8.1.21"><i class="fa fa-check"></i><b>8.1.21</b> 招聘</a></li>
</ul></li>
<li class="chapter" data-level="8.2" data-path="references.html"><a href="references.html#section-8.2"><i class="fa fa-check"></i><b>8.2</b> 宏基因组</a><ul>
<li class="chapter" data-level="8.2.1" data-path="references.html"><a href="references.html#section-8.2.1"><i class="fa fa-check"></i><b>8.2.1</b> 精选文章推荐</a></li>
<li class="chapter" data-level="8.2.2" data-path="references.html"><a href="references.html#section-8.2.2"><i class="fa fa-check"></i><b>8.2.2</b> 培训、会议、征稿、招聘</a></li>
<li class="chapter" data-level="8.2.3" data-path="references.html"><a href="references.html#section-8.2.3"><i class="fa fa-check"></i><b>8.2.3</b> 科研经验</a></li>
<li class="chapter" data-level="8.2.4" data-path="references.html"><a href="references.html#section-8.2.4"><i class="fa fa-check"></i><b>8.2.4</b> 软件和数据库使用</a></li>
<li class="chapter" data-level="8.2.5" data-path="references.html"><a href="references.html#section-8.2.5"><i class="fa fa-check"></i><b>8.2.5</b> 扩增子学习三步曲</a></li>
<li class="chapter" data-level="8.2.6" data-path="py3-ct.html"><a href="py3-ct.html#-1"><i class="fa fa-check"></i><b>8.2.6</b> 宏基因组分析专题</a></li>
<li class="chapter" data-level="8.2.7" data-path="references.html"><a href="references.html#r"><i class="fa fa-check"></i><b>8.2.7</b> R统计绘图</a></li>
<li class="chapter" data-level="8.2.8" data-path="references.html"><a href="references.html#section-8.2.8"><i class="fa fa-check"></i><b>8.2.8</b> 实验设计与技术</a></li>
<li class="chapter" data-level="8.2.9" data-path="references.html"><a href="references.html#section-8.2.9"><i class="fa fa-check"></i><b>8.2.9</b> 基础知识</a></li>
<li class="chapter" data-level="8.2.10" data-path="references.html"><a href="references.html#section-8.2.10"><i class="fa fa-check"></i><b>8.2.10</b> 必读综述</a></li>
<li class="chapter" data-level="8.2.11" data-path="references.html"><a href="references.html#section-8.2.11"><i class="fa fa-check"></i><b>8.2.11</b> 高分文章套路解读</a></li>
<li class="chapter" data-level="8.2.12" data-path="pythonbasic.html"><a href="pythonbasic.html#-"><i class="fa fa-check"></i><b>8.2.12</b> 科普视频-寓教于乐</a></li>
<li class="chapter" data-level="8.2.13" data-path="references.html"><a href="references.html#section-8.2.13"><i class="fa fa-check"></i><b>8.2.13</b> 友军文章汇总推荐</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="9" data-path="company-intro.html"><a href="company-intro.html"><i class="fa fa-check"></i><b>9</b> 公司简介</a></li>
<li class="divider"></li>
<li><a href="mailto:ct@ehbio.com" target="blank">ct@ehbio.com</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Python3学习教程</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="numpy_scipy" class="section level1">
<h1><span class="header-section-number">6</span> Python科学计算</h1>
<div id="numpy" class="section level2">
<h2><span class="header-section-number">6.1</span> NumPy</h2>
<div id="numpy" class="section level3">
<h3><span class="header-section-number">6.1.1</span> NumPy数组</h3>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">import</span> numpy <span class="im">as</span> np
<span class="im">import</span> numpy.random <span class="im">as</span> rand
<span class="im">import</span> matplotlib.pyplot <span class="im">as</span> plt</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## Numpy克服了Python中list速度慢的缺点，创建了新数据类型ndarray</span>
<span class="co">## ndarray的每列元素一般是相同类型的，是浮点数、整型或字符串，这点和list不同</span>
<span class="co">## 下面的例子测试对比了ndarray和list速度上的区别</span>
<span class="co">## 首先建立一个0...10^7-1的10^7个元素的数组</span>
arr<span class="op">=</span>np.arange(<span class="fl">1e7</span>)
<span class="co">## 将ndarray转换为list</span>
larr<span class="op">=</span>arr.tolist()
<span class="co">## 工具函数，模拟ndarray把list的每个元素乘以一个标量的运算</span>
<span class="kw">def</span> list_times(alist, scalar):
    <span class="cf">for</span> i, val <span class="op">in</span> <span class="bu">enumerate</span>(alist):
        alist[i]<span class="op">=</span>val<span class="op">*</span>scalar
    <span class="cf">return</span> alist
<span class="co">## 比较ndarray和list每个元素乘以一个标量的运行时间</span>
<span class="co">## 在我的电脑上，ndarray乘以一个标量的运行时间要比list快约33倍</span>
<span class="op">%</span>timeit arr<span class="op">*</span><span class="fl">1.1</span>
<span class="op">%</span>timeit list_times(larr,<span class="fl">1.1</span>)</code></pre></div>
<pre><code>37 ms ± 1.49 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
1.22 s ± 41.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 两个2维ndarray相乘是对应元素相乘，而两个matrix相乘是进行矩阵乘法</span>
<span class="co">## matrix只有2维，以下代码运行会出错：shape too large to be a matrix</span>
arr<span class="op">=</span>np.zeros((<span class="dv">3</span>,<span class="dv">3</span>,<span class="dv">3</span>))
mat<span class="op">=</span>np.matrix(arr)</code></pre></div>
<pre><code>---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

&lt;ipython-input-2-667d2452a8e0&gt; in &lt;module&gt;()
      2 # matrix只有2维，以下代码运行会出错
      3 arr=np.zeros((3,3,3))
----&gt; 4 mat=np.matrix(arr)


~/anaconda3/lib/python3.6/site-packages/numpy/matrixlib/defmatrix.py in __new__(subtype, data, dtype, copy)
    224             else:
    225                 intype = N.dtype(dtype)
--&gt; 226             new = data.view(subtype)
    227             if intype != data.dtype:
    228                 return new.astype(intype)


~/anaconda3/lib/python3.6/site-packages/numpy/matrixlib/defmatrix.py in __array_finalize__(self, obj)
    269                 return
    270             elif (ndim &gt; 2):
--&gt; 271                 raise ValueError(&quot;shape too large to be a matrix.&quot;)
    272         else:
    273             newshape = self.shape


ValueError: shape too large to be a matrix.</code></pre>
<div id="section-6.1.1.1" class="section level4">
<h4><span class="header-section-number">6.1.1.1</span> 创建数组和定义数据类型</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 在NumPy中，创建数组有多种方法</span>
<span class="co">## 首先创建一个list，然后用np.array()方法把它包裹起来</span>
alist<span class="op">=</span>[<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]
arr<span class="op">=</span>np.array(alist)
arr</code></pre></div>
<pre><code>array([1, 2, 3])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建一个5个元素的全零数组</span>
arr<span class="op">=</span>np.zeros(<span class="dv">5</span>)
arr</code></pre></div>
<pre><code>array([ 0.,  0.,  0.,  0.,  0.])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建一个从0到99的数组</span>
arr<span class="op">=</span>np.arange(<span class="dv">100</span>)
arr</code></pre></div>
<pre><code>array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
       34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
       51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
       68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
       85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 10到99的数组？</span>
arr<span class="op">=</span>np.arange(<span class="dv">10</span>,<span class="dv">100</span>)
arr</code></pre></div>
<pre><code>array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
       27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
       44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
       61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
       78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
       95, 96, 97, 98, 99])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 0到1，中间有100步，linear space</span>
arr<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">100</span>)
arr</code></pre></div>
<pre><code>array([ 0.        ,  0.01010101,  0.02020202,  0.03030303,  0.04040404,
        0.05050505,  0.06060606,  0.07070707,  0.08080808,  0.09090909,
        0.1010101 ,  0.11111111,  0.12121212,  0.13131313,  0.14141414,
        0.15151515,  0.16161616,  0.17171717,  0.18181818,  0.19191919,
        0.2020202 ,  0.21212121,  0.22222222,  0.23232323,  0.24242424,
        0.25252525,  0.26262626,  0.27272727,  0.28282828,  0.29292929,
        0.3030303 ,  0.31313131,  0.32323232,  0.33333333,  0.34343434,
        0.35353535,  0.36363636,  0.37373737,  0.38383838,  0.39393939,
        0.4040404 ,  0.41414141,  0.42424242,  0.43434343,  0.44444444,
        0.45454545,  0.46464646,  0.47474747,  0.48484848,  0.49494949,
        0.50505051,  0.51515152,  0.52525253,  0.53535354,  0.54545455,
        0.55555556,  0.56565657,  0.57575758,  0.58585859,  0.5959596 ,
        0.60606061,  0.61616162,  0.62626263,  0.63636364,  0.64646465,
        0.65656566,  0.66666667,  0.67676768,  0.68686869,  0.6969697 ,
        0.70707071,  0.71717172,  0.72727273,  0.73737374,  0.74747475,
        0.75757576,  0.76767677,  0.77777778,  0.78787879,  0.7979798 ,
        0.80808081,  0.81818182,  0.82828283,  0.83838384,  0.84848485,
        0.85858586,  0.86868687,  0.87878788,  0.88888889,  0.8989899 ,
        0.90909091,  0.91919192,  0.92929293,  0.93939394,  0.94949495,
        0.95959596,  0.96969697,  0.97979798,  0.98989899,  1.        ])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## log10空间里1到10的数组，中间有100步</span>
<span class="co">## numpy.logspace(start, stop, num=50, endpoint=True, base=10.0, dtype=None)</span>
<span class="co">## base**start是数组的第一个元素，base**stop是数组的最后一个元素</span>
arr<span class="op">=</span>np.logspace(<span class="dv">0</span>,<span class="dv">1</span>,<span class="dv">100</span>,base<span class="op">=</span><span class="fl">10.0</span>)
arr</code></pre></div>
<pre><code>array([  1.        ,   1.02353102,   1.04761575,   1.07226722,
         1.09749877,   1.12332403,   1.149757  ,   1.17681195,
         1.20450354,   1.23284674,   1.26185688,   1.29154967,
         1.32194115,   1.35304777,   1.38488637,   1.41747416,
         1.45082878,   1.48496826,   1.51991108,   1.55567614,
         1.59228279,   1.62975083,   1.66810054,   1.70735265,
         1.7475284 ,   1.78864953,   1.83073828,   1.87381742,
         1.91791026,   1.96304065,   2.009233  ,   2.05651231,
         2.10490414,   2.15443469,   2.20513074,   2.25701972,
         2.3101297 ,   2.36448941,   2.42012826,   2.47707636,
         2.53536449,   2.59502421,   2.65608778,   2.71858824,
         2.7825594 ,   2.84803587,   2.91505306,   2.98364724,
         3.05385551,   3.12571585,   3.19926714,   3.27454916,
         3.35160265,   3.43046929,   3.51119173,   3.59381366,
         3.67837977,   3.76493581,   3.85352859,   3.94420606,
         4.03701726,   4.1320124 ,   4.22924287,   4.32876128,
         4.43062146,   4.53487851,   4.64158883,   4.75081016,
         4.86260158,   4.97702356,   5.09413801,   5.21400829,
         5.33669923,   5.46227722,   5.59081018,   5.72236766,
         5.85702082,   5.9948425 ,   6.13590727,   6.28029144,
         6.42807312,   6.57933225,   6.73415066,   6.8926121 ,
         7.05480231,   7.22080902,   7.39072203,   7.56463328,
         7.74263683,   7.92482898,   8.11130831,   8.30217568,
         8.49753436,   8.69749003,   8.90215085,   9.11162756,
         9.32603347,   9.54548457,   9.77009957,  10.        ])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建一个5*5的全零数组</span>
image<span class="op">=</span>np.zeros((<span class="dv">5</span>,<span class="dv">5</span>))
image</code></pre></div>
<pre><code>array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建一个5*5*5的全1的cube</span>
<span class="co">## astype()方法将数组的元素全部设为整型</span>
cube<span class="op">=</span>np.zeros((<span class="dv">5</span>,<span class="dv">5</span>,<span class="dv">5</span>)).astype(<span class="bu">int</span>)<span class="op">+</span><span class="dv">1</span>
cube</code></pre></div>
<pre><code>array([[[1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1]],

       [[1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1]],

       [[1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1]],

       [[1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1]],

       [[1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1]]])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 或者用更简单的方法创建全1数组，元素是16位浮点精度</span>
cube<span class="op">=</span>np.ones((<span class="dv">5</span>,<span class="dv">5</span>,<span class="dv">5</span>)).astype(np.float16)
cube</code></pre></div>
<pre><code>array([[[ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.]],

       [[ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.]],

       [[ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.]],

       [[ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.]],

       [[ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.],
        [ 1.,  1.,  1.,  1.,  1.]]], dtype=float16)</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## NumPy在生成数组时，默认使用系统的字长来创建数组元素</span>
<span class="co">## 在64位的Python环境中，数组元素默认为64位精度的浮点数</span>
<span class="co">## 这种设定消耗大量内存，很多时候并非必要</span>
<span class="co">## 在创建数组时，用户可以自己设定元素的精度，即把dtype参数设为int, numpy.float16, </span>
<span class="co">## numpy.float32, numpy.float64</span>

<span class="co">## 下面定义了一个全零的整型数组</span>
arr1<span class="op">=</span>np.zeros(<span class="dv">2</span>,dtype<span class="op">=</span><span class="bu">int</span>)
<span class="co">## 下面定义了一个全零的浮点型数组</span>
arr2<span class="op">=</span>np.zeros(<span class="dv">2</span>,dtype<span class="op">=</span>np.float32)
<span class="bu">print</span>(arr1)
<span class="bu">print</span>(arr2)</code></pre></div>
<pre><code>[0 0]
[ 0.  0.]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 数组变形</span>
<span class="co">## 创建一个125个元素的数组</span>
arr1d<span class="op">=</span>np.arange(<span class="dv">125</span>)
<span class="co">## 把数组变形为5*5*5的三维数组</span>
arr3d<span class="op">=</span>arr1d.reshape((<span class="dv">5</span>,<span class="dv">5</span>,<span class="dv">5</span>))
<span class="co">## 另一种效果相同的变形方法</span>
arr3d<span class="op">=</span>np.reshape(arr1d,(<span class="dv">5</span>,<span class="dv">5</span>,<span class="dv">5</span>))
<span class="bu">print</span>(arr3d)
<span class="co">## 把高维数组变形为一维数组</span>
arr4d<span class="op">=</span>np.zeros((<span class="dv">10</span>,<span class="dv">10</span>,<span class="dv">10</span>,<span class="dv">10</span>))
arr1d<span class="op">=</span>arr4d.ravel()
<span class="bu">print</span>(arr1d.shape)
<span class="co">## 值得注意的是，数组的变形只是改变观察数组的角度，</span>
<span class="co">## 并没有新创建数组，变形后的数组和变形前的数组使用的是相同的内存空间</span>
<span class="co">## 因此改动其中一个数组的元素，另一个数组的元素也会跟着改变</span>
<span class="co">## 要创建内存中完全不同的数组，需要使用numpy.copy函数</span></code></pre></div>
<pre><code>[[[  0   1   2   3   4]
  [  5   6   7   8   9]
  [ 10  11  12  13  14]
  [ 15  16  17  18  19]
  [ 20  21  22  23  24]]

 [[ 25  26  27  28  29]
  [ 30  31  32  33  34]
  [ 35  36  37  38  39]
  [ 40  41  42  43  44]
  [ 45  46  47  48  49]]

 [[ 50  51  52  53  54]
  [ 55  56  57  58  59]
  [ 60  61  62  63  64]
  [ 65  66  67  68  69]
  [ 70  71  72  73  74]]

 [[ 75  76  77  78  79]
  [ 80  81  82  83  84]
  [ 85  86  87  88  89]
  [ 90  91  92  93  94]
  [ 95  96  97  98  99]]

 [[100 101 102 103 104]
  [105 106 107 108 109]
  [110 111 112 113 114]
  [115 116 117 118 119]
  [120 121 122 123 124]]]
(10000,)</code></pre>
</div>
<div id="record-arrays" class="section level4">
<h4><span class="header-section-number">6.1.1.2</span> 记录数组（Record Arrays）</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 数组一般来说是只包含一种数据类型，不过有些时候数组可以用来存储更复杂的数据结构，</span>
<span class="co">## 每列由不同的数据类型组成，叫做记录数组</span>
<span class="co">## 创建一个全零数组，定义列的类型（i4：32位整数，f4：32位浮点数，a10：长度为10的字符串）</span>
recarr<span class="op">=</span>np.zeros((<span class="dv">2</span>,),dtype<span class="op">=</span>(<span class="st">&#39;i4,f4,a10&#39;</span>))
<span class="co">## 创建我们想放进recarr数组的列</span>
col1<span class="op">=</span>np.arange(<span class="dv">2</span>)<span class="op">+</span><span class="dv">1</span> <span class="co"># array([1,2])</span>
col2<span class="op">=</span>np.arange(<span class="dv">2</span>,dtype<span class="op">=</span>np.float32) <span class="co"># array([0.,1.], dtype=float32)</span>
col3<span class="op">=</span>[<span class="st">&quot;Hello&quot;</span>,<span class="st">&quot;World&quot;</span>]
<span class="co">## 创建一个列表，整合上面3列</span>
toadd<span class="op">=</span><span class="bu">list</span>(<span class="bu">zip</span>(col1,col2,col3))
<span class="co">## 给recarr赋值</span>
recarr[:]<span class="op">=</span>toadd
recarr
<span class="co">## 结果中字符串前的&quot;b&quot;：python3.x里默认的str是(py2.x里的)unicode, </span>
<span class="co">## bytes是(py2.x)的str, b”“前缀代表的就是bytes</span></code></pre></div>
<pre><code>array([(1,  0., b&#39;Hello&#39;), (2,  1., b&#39;World&#39;)],
      dtype=[(&#39;f0&#39;, &#39;&lt;i4&#39;), (&#39;f1&#39;, &#39;&lt;f4&#39;), (&#39;f2&#39;, &#39;S10&#39;)])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 给每一列赋一个名字，默认的名字是f0, f1, f2</span>
recarr.dtype.names<span class="op">=</span>(<span class="st">&quot;Integers&quot;</span>,<span class="st">&quot;Floats&quot;</span>,<span class="st">&quot;Strings&quot;</span>)
<span class="co">## 用列的名字访问一列</span>
recarr[<span class="st">&quot;Integers&quot;</span>]</code></pre></div>
<pre><code>array([1, 2], dtype=int32)</code></pre>
</div>
<div id="section-6.1.1.3" class="section level4">
<h4><span class="header-section-number">6.1.1.3</span> 索引和切割</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 要返回任意列，在Python的列表里不太容易，但在NumPy数组里很方便</span>
<span class="co">## 定义一个列表</span>
alist<span class="op">=</span>[[<span class="dv">1</span>,<span class="dv">2</span>],[<span class="dv">3</span>,<span class="dv">4</span>]]
<span class="co">## 把列表转换为一个NumPy数组</span>
arr<span class="op">=</span>np.array(alist)
<span class="co">## 打印(0,1)元素</span>
<span class="bu">print</span>(arr[<span class="dv">0</span>,<span class="dv">1</span>])
<span class="co">## 打印第二列</span>
<span class="bu">print</span>(arr[:,<span class="dv">1</span>])
<span class="co">## 打印第二行</span>
<span class="bu">print</span>(arr[<span class="dv">1</span>,:])</code></pre></div>
<pre><code>2
[2 4]
[3 4]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 条件索引，常用numpy.where()，可以返回数组中需要的索引，基于条件，不考虑维度</span>
<span class="co">## 创建一个数组</span>
arr<span class="op">=</span>np.arange(<span class="dv">5</span>)
<span class="co">## 创建索引数组</span>
index<span class="op">=</span>np.where(arr<span class="op">&gt;</span><span class="dv">2</span>)
<span class="bu">print</span>(index)
<span class="co">## 根据索引创建需要的数组</span>
new_arr1<span class="op">=</span>arr[index]
<span class="bu">print</span>(new_arr)
<span class="co">## 使用np.delete()删除特定的索引</span>
<span class="co">## 删除index中包含的元素</span>
new_arr2<span class="op">=</span>np.delete(arr,index)
<span class="bu">print</span>(new_arr2)
<span class="co">## 用简单的布尔列表作为下标返回需要的数组</span>
<span class="co">## 使用布尔索引获得需要的元素比np.where()要迅速，并且可以通过~index轻易地反转布尔数组</span>
index<span class="op">=</span>arr<span class="op">&gt;</span><span class="dv">2</span>
<span class="bu">print</span>(index)
new_arr<span class="op">=</span>arr[index]
<span class="bu">print</span>(new_arr)</code></pre></div>
<pre><code>(array([3, 4]),)
[3 4]
[0 1 2]
[False False False  True  True]
[3 4]</code></pre>
</div>
</div>
<div id="numpy" class="section level3">
<h3><span class="header-section-number">6.1.2</span> 布尔语句和NumPy数组</h3>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建一个图片</span>
img1<span class="op">=</span>np.zeros((<span class="dv">20</span>,<span class="dv">20</span>))<span class="op">+</span><span class="dv">3</span>
img1[<span class="dv">4</span>:<span class="op">-</span><span class="dv">4</span>,<span class="dv">4</span>:<span class="op">-</span><span class="dv">4</span>]<span class="op">=</span><span class="dv">6</span>
img1[<span class="dv">7</span>:<span class="op">-</span><span class="dv">7</span>,<span class="dv">7</span>:<span class="op">-</span><span class="dv">7</span>]<span class="op">=</span><span class="dv">9</span>
<span class="co">## 见Plot A</span>

<span class="co">## compound_index变量存储所有大于2或小于6的下标</span>
index1<span class="op">=</span>img1<span class="op">&gt;</span><span class="dv">2</span>
index2<span class="op">=</span>img1<span class="op">&lt;</span><span class="dv">6</span>
compound_index<span class="op">=</span>index1 <span class="op">&amp;</span> index2

<span class="co">## 复合索引的语句也可以写成这样：</span>
compound_index<span class="op">=</span>(img1<span class="op">&gt;</span><span class="dv">3</span>) <span class="op">&amp;</span> (img1<span class="op">&lt;</span><span class="dv">7</span>)
img2<span class="op">=</span>np.copy(img1)
img2[compound_index]<span class="op">=</span><span class="dv">0</span>
<span class="co">## 见Plot B</span>

<span class="co">## 使用更复杂的布尔数组</span>
index3<span class="op">=</span>img1<span class="op">==</span><span class="dv">9</span>
index4<span class="op">=</span>(index1 <span class="op">&amp;</span> index2) <span class="op">|</span> index3
img3<span class="op">=</span>np.copy(img1)
img3[index4]<span class="op">=</span><span class="dv">0</span>
<span class="co">## 见Plot C</span></code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 仅变更数组中选中变量的值</span>
<span class="co">## 依据标准正态分布（均值为0，方差为1）创建一个100个随机元素的数组</span>
a<span class="op">=</span>rand.randn(<span class="dv">100</span>)
<span class="bu">print</span>(a)
<span class="co">## 去掉不需要的元素</span>
index<span class="op">=</span>a<span class="op">&gt;</span><span class="fl">0.2</span>
b<span class="op">=</span>a[index]
<span class="co">## 在选出的元素上应用某些运算</span>
b<span class="op">=</span>b<span class="op">**</span><span class="dv">2-2</span>
<span class="co">## 把修改过的元素仍然放回原来的数组，这样就完成了对数组中某些值得变更</span>
a[index]<span class="op">=</span>b
<span class="bu">print</span>(a)</code></pre></div>
<pre><code>[-1.80712517 -0.13170284  1.93343213  0.80721035  2.52144275  0.16195953
  0.11878839  1.88961184 -0.75881407 -1.22866865 -0.73857745  0.64046896
  0.73563193  0.71783485 -0.37645069  0.90120663 -0.59161068 -1.16366655
 -0.50663906 -0.36447979 -1.8654699   0.92406343  0.8004173  -1.41016169
  0.32592465  0.725013    0.29738016 -2.21113871 -0.68122701  0.66455187
 -0.32413105  1.13627295  0.13185364  1.38536725  0.19462378 -1.80775106
 -0.06199759 -1.30422952 -0.30685345  0.08940313 -0.67023186 -0.15051653
 -0.15879759  1.35984567 -0.2328225  -1.7265208   0.67232358 -0.59098342
 -1.20227104 -1.08216219 -0.53158487  1.33859499  0.66763318 -0.56431746
  0.75334062  1.44683156  1.9512399   0.42510796  0.34020597  0.72372802
 -0.10372294  0.184639    0.01761624 -0.69082466  0.36432908 -0.56651026
  0.21865567 -0.42096267 -0.73512854 -0.05493638 -1.94869892  0.76399321
  1.41936848  0.05750032 -0.12937963 -0.02329108 -1.47156894 -0.84254776
  0.75245785  0.07682322  0.96333808  0.92090036  0.76489123  0.63520238
 -0.08737849 -1.2083732   0.21328152  0.92891946  0.26792553  0.0672728
 -1.74821241  0.69335543 -0.60076278 -0.11200103 -1.4392716  -0.35400569
 -0.05871362  0.8178716   1.08160928  0.77033013]
[-1.80712517 -0.13170284  1.73815979 -1.34841145  4.35767354  0.16195953
  0.11878839  1.57063289 -0.75881407 -1.22866865 -0.73857745 -1.58979952
 -1.45884566 -1.48471313 -0.37645069 -1.1878266  -0.59161068 -1.16366655
 -0.50663906 -0.36447979 -1.8654699  -1.14610677 -1.35933214 -1.41016169
 -1.89377312 -1.47435616 -1.91156504 -2.21113871 -0.68122701 -1.55837081
 -0.32413105 -0.70888379  0.13185364 -0.08075759  0.19462378 -1.80775106
 -0.06199759 -1.30422952 -0.30685345  0.08940313 -0.67023186 -0.15051653
 -0.15879759 -0.15081976 -0.2328225  -1.7265208  -1.547981   -0.59098342
 -1.20227104 -1.08216219 -0.53158487 -0.20816344 -1.55426593 -0.56431746
 -1.43247792  0.09332155  1.80733714 -1.81928322 -1.8842599  -1.47621775
 -0.10372294  0.184639    0.01761624 -0.69082466 -1.86726432 -0.56651026
 -1.9521897  -0.42096267 -0.73512854 -0.05493638 -1.94869892 -1.41631438
  0.01460689  0.05750032 -0.12937963 -0.02329108 -1.47156894 -0.84254776
 -1.43380718  0.07682322 -1.07197974 -1.15194253 -1.4149414  -1.59651793
 -0.08737849 -1.2083732  -1.95451099 -1.13710863 -1.92821591  0.0672728
 -1.74821241 -1.51925824 -0.60076278 -0.11200103 -1.4392716  -0.35400569
 -0.05871362 -1.33108605 -0.83012136 -1.40659148]</code></pre>
</div>
<div id="numpy" class="section level3">
<h3><span class="header-section-number">6.1.3</span> NumPy读写文件</h3>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## NumPy读文本文件中的矩阵</span>
arr<span class="op">=</span>np.loadtxt(<span class="st">&quot;data5/somefile.txt&quot;</span>)
arr</code></pre></div>
<pre><code>array([[  2.,   3.,   5.],
       [  7.,  11.,  13.],
       [ 17.,  19.,  23.]])</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## NumPy写矩阵到文本文件中</span>
<span class="co">## numpy.savetxt(fname, X, fmt=&#39;%.18e&#39;, delimiter=&#39; &#39;, newline=&#39;\n&#39;, </span>
<span class="co">##  header=&#39;&#39;, footer=&#39;&#39;, comments=&#39;# &#39;, encoding=None)[source]</span>
np.savetxt(<span class="st">&quot;data5/somenewfile.txt&quot;</span>,arr,<span class="st">&quot;</span><span class="sc">%d</span><span class="st">&quot;</span>,<span class="st">&quot;</span><span class="ch">\t</span><span class="st">&quot;</span>)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## loadtxt()读取文件中复杂的数据结构</span>
recarr<span class="op">=</span>np.loadtxt(<span class="st">&quot;data5/example.txt&quot;</span>, dtype<span class="op">=</span>{
        <span class="st">&quot;names&quot;</span>:(<span class="st">&quot;Gene_ID&quot;</span>,<span class="st">&quot;Sample1&quot;</span>,<span class="st">&quot;Sample2&quot;</span>,<span class="st">&quot;Sample3&quot;</span>),
        <span class="co">&quot;formats&quot;</span>:(<span class="st">&quot;S6&quot;</span>,<span class="st">&quot;f4&quot;</span>,<span class="st">&quot;f4&quot;</span>,<span class="st">&quot;f4&quot;</span>)})
recarr</code></pre></div>
<pre><code>array([(b&#39;Gene1&#39;,   2.29999995,   5.69999981,  11.13000011),
       (b&#39;Gene2&#39;,  17.19000053,  23.29000092,  31.37000084)],
      dtype=[(&#39;Gene_ID&#39;, &#39;S6&#39;), (&#39;Sample1&#39;, &#39;&lt;f4&#39;), 
      (&#39;Sample2&#39;, &#39;&lt;f4&#39;), (&#39;Sample3&#39;, &#39;&lt;f4&#39;)])</code></pre>
</div>
<div id="numpymath" class="section level3">
<h3><span class="header-section-number">6.1.4</span> NumPy的Math模块</h3>
<div id="section-6.1.4.1" class="section level4">
<h4><span class="header-section-number">6.1.4.1</span> 线性代数</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 解矩阵方程AX=B</span>
<span class="co">## 定义矩阵A, B</span>
A<span class="op">=</span>np.matrix([[<span class="dv">3</span>,<span class="dv">6</span>,<span class="op">-</span><span class="dv">5</span>],[<span class="dv">1</span>,<span class="op">-</span><span class="dv">3</span>,<span class="dv">2</span>],[<span class="dv">5</span>,<span class="op">-</span><span class="dv">1</span>,<span class="dv">4</span>]])
B<span class="op">=</span>np.matrix([[<span class="dv">12</span>],[<span class="op">-</span><span class="dv">2</span>],[<span class="dv">10</span>]])
<span class="co">## 解矩阵方程，等号两边同时左乘A^(-1)</span>
X<span class="op">=</span>A<span class="op">**-</span><span class="dv">1</span><span class="op">*</span>B
<span class="bu">print</span>(X)</code></pre></div>
<pre><code>[[ 1.75]
 [ 1.75]
 [ 0.75]]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 使用np.array，更快</span>
a<span class="op">=</span>np.array([[<span class="dv">3</span>,<span class="dv">6</span>,<span class="op">-</span><span class="dv">5</span>],[<span class="dv">1</span>,<span class="op">-</span><span class="dv">3</span>,<span class="dv">2</span>],[<span class="dv">5</span>,<span class="op">-</span><span class="dv">1</span>,<span class="dv">4</span>]])
b<span class="op">=</span>np.array([[<span class="dv">12</span>],[<span class="op">-</span><span class="dv">2</span>],[<span class="dv">10</span>]])
x<span class="op">=</span>np.linalg.inv(a).dot(b)
<span class="bu">print</span>(x)</code></pre></div>
<pre><code>[[ 1.75]
 [ 1.75]
 [ 0.75]]</code></pre>
</div>
</div>
</div>
<div id="scipy" class="section level2">
<h2><span class="header-section-number">6.2</span> SciPy</h2>
<div id="section-6.2.1" class="section level3">
<h3><span class="header-section-number">6.2.1</span> 最优化和最小化</h3>
<div id="section-6.2.1.1" class="section level4">
<h4><span class="header-section-number">6.2.1.1</span> 数据建模和拟合</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">from</span> scipy.optimize <span class="im">import</span> curve_fit</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 拟合线性分布</span>
<span class="co">## 创建一个函数，用来建模和创建数据</span>
<span class="kw">def</span> func(x,a,b):
    <span class="cf">return</span> a<span class="op">*</span>x<span class="op">+</span>b

<span class="co">## 生成干净的数据</span>
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">10</span>,<span class="dv">100</span>)
y<span class="op">=</span>func(x,<span class="dv">1</span>,<span class="dv">2</span>)

<span class="co">## 加入噪声</span>
yn<span class="op">=</span>y<span class="fl">+0.9</span><span class="op">*</span>np.random.normal(size<span class="op">=</span><span class="bu">len</span>(x))

<span class="co">## 在有噪声的数据上应用curve_fit</span>
<span class="co">## popt返回给定模型（func）下的参数的最佳拟合值</span>
<span class="co">## pcov返回一个矩阵表示拟合的质量，矩阵对角线上的值是各参数的方差</span>
popt,pcov<span class="op">=</span>curve_fit(func,x,yn)

<span class="bu">print</span>(popt)</code></pre></div>
<pre><code>[ 1.06107439  1.7517619 ]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig<span class="op">=</span>plt.figure()

ax1<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">1</span>)
ax2<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>)
ax3<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">3</span>)
ax4<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">4</span>)

ax1.scatter(x,y,<span class="dv">1</span>)

ax2.scatter(x,yn,<span class="dv">1</span>)

ax3.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax3.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>x<span class="op">+</span>popt[<span class="dv">1</span>],<span class="st">&quot;blue&quot;</span>)

ax4.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax4.plot(x,y,<span class="st">&quot;green&quot;</span>)
ax4.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>x<span class="op">+</span>popt[<span class="dv">1</span>],<span class="st">&quot;blue&quot;</span>)

plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_35_0.png" width="100%" style="display: block; margin: auto;" /></p>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 拟合高斯分布</span>
<span class="co">## 创建一个函数，用来建模和创建数据</span>
<span class="kw">def</span> func(x,a,b,c):
    <span class="cf">return</span> a<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>b)<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>c<span class="op">**</span><span class="dv">2</span>))

<span class="co">## 生成干净的数据</span>
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">10</span>,<span class="dv">100</span>)
y<span class="op">=</span>func(x,<span class="dv">1</span>,<span class="dv">5</span>,<span class="dv">2</span>)

<span class="co">## 加入噪声</span>
yn<span class="op">=</span>y<span class="fl">+0.2</span><span class="op">*</span>np.random.normal(size<span class="op">=</span><span class="bu">len</span>(x))

<span class="co">## 在有噪声的数据上应用curve_fit</span>
<span class="co">## popt返回给定模型（func）下的参数的最佳拟合值</span>
<span class="co">## pcov返回一个矩阵表示拟合的质量，矩阵对角线上的值是各参数的方差</span>
popt, pcov <span class="op">=</span> curve_fit(func, x, yn)

<span class="bu">print</span>(popt)</code></pre></div>
<pre><code>[ 1.03822218  5.01637962 -1.88413558]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig<span class="op">=</span>plt.figure()

ax1<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">1</span>)
ax2<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>)
ax3<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">3</span>)
ax4<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">4</span>)

ax1.scatter(x,y,<span class="dv">1</span>)

ax2.scatter(x,yn,<span class="dv">1</span>)

ax3.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax3.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">2</span>]<span class="op">**</span><span class="dv">2</span>)),<span class="st">&quot;blue&quot;</span>)

ax4.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax4.plot(x,y,<span class="st">&quot;green&quot;</span>)
ax4.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">2</span>]<span class="op">**</span><span class="dv">2</span>)),<span class="st">&quot;blue&quot;</span>)

plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_37_0.png" width="100%" style="display: block; margin: auto;" /></p>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 拟合两个高斯分布的线性组合</span>
<span class="co">## 创建一个函数，用来建模和创建数据</span>
<span class="kw">def</span> func(x,a0,b0,c0,a1,b1,c1):
    <span class="cf">return</span> a0<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>b0)<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>c0<span class="op">**</span><span class="dv">2</span>))<span class="op">+</span>a1<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>b1)<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>c1<span class="op">**</span><span class="dv">2</span>))

<span class="co">## 生成干净的数据</span>
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">20</span>,<span class="dv">200</span>)
y<span class="op">=</span>func(x,<span class="dv">1</span>,<span class="dv">3</span>,<span class="dv">1</span>,<span class="op">-</span><span class="dv">2</span>,<span class="dv">15</span>,<span class="fl">0.5</span>)

<span class="co">## 加入噪声</span>
yn<span class="op">=</span>y<span class="fl">+0.2</span><span class="op">*</span>np.random.normal(size<span class="op">=</span><span class="bu">len</span>(x))

<span class="co">## 在有噪声的数据上应用curve_fit</span>
<span class="co">## popt返回给定模型（func）下的参数的最佳拟合值</span>
<span class="co">## pcov返回一个矩阵表示拟合的质量，矩阵对角线上的值是各参数的方差</span>
popt, pcov <span class="op">=</span> curve_fit(func, x, yn)

<span class="bu">print</span>(popt)</code></pre></div>
<pre><code>[ -2.04644312  14.99180963   0.50668406   1.05196114   2.97782597
   0.99894884]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig<span class="op">=</span>plt.figure()

ax1<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">1</span>)
ax2<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">2</span>)
ax3<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">3</span>)
ax4<span class="op">=</span>fig.add_subplot(<span class="dv">2</span>,<span class="dv">2</span>,<span class="dv">4</span>)

ax1.scatter(x,y,<span class="dv">1</span>)

ax2.scatter(x,yn,<span class="dv">1</span>)

ax3.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax3.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">2</span>]<span class="op">**</span><span class="dv">2</span>))<span class="op">+</span>
        popt[<span class="dv">3</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">4</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">5</span>]<span class="op">**</span><span class="dv">2</span>)),<span class="st">&quot;blue&quot;</span>)

ax4.scatter(x,yn,<span class="dv">1</span>,<span class="st">&quot;red&quot;</span>)
ax4.plot(x,y,<span class="st">&quot;green&quot;</span>)
ax4.plot(x,popt[<span class="dv">0</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">1</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">2</span>]<span class="op">**</span><span class="dv">2</span>))<span class="op">+</span>
        popt[<span class="dv">3</span>]<span class="op">*</span>np.exp(<span class="op">-</span>(x<span class="op">-</span>popt[<span class="dv">4</span>])<span class="op">**</span><span class="dv">2</span><span class="op">/</span>(<span class="dv">2</span><span class="op">*</span>popt[<span class="dv">5</span>]<span class="op">**</span><span class="dv">2</span>)),<span class="st">&quot;blue&quot;</span>)
ax4.legend(loc<span class="op">=</span><span class="dv">0</span>, bbox_to_anchor<span class="op">=</span>(<span class="dv">1</span>,<span class="dv">1</span>))

plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_39_0.png" width="100%" style="display: block; margin: auto;" /></p>
</div>
<div id="section-6.2.1.2" class="section level4">
<h4><span class="header-section-number">6.2.1.2</span> 函数的解</h4>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">from</span> scipy.optimize <span class="im">import</span> fsolve</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">line<span class="op">=</span><span class="kw">lambda</span> x:x<span class="dv">+3</span>
solution<span class="op">=</span>fsolve(line,<span class="op">-</span><span class="dv">2</span>)
<span class="bu">print</span>(solution)</code></pre></div>
<pre><code>[-3.]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig <span class="op">=</span> plt.figure()
ax<span class="op">=</span>fig.add_subplot(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>)
x<span class="op">=</span>np.linspace(<span class="op">-</span><span class="dv">10</span>,<span class="dv">10</span>,<span class="dv">100</span>)
zeros<span class="op">=</span>np.zeros(<span class="dv">100</span>)
ax.plot(x,line(x),<span class="st">&quot;blue&quot;</span>,label<span class="op">=</span><span class="st">&quot;Function&quot;</span>)
ax.plot(x,zeros,<span class="st">&quot;g--&quot;</span>,label<span class="op">=</span><span class="st">&quot;y=0&quot;</span>)
ax.scatter(solution,line(solution),<span class="dv">25</span>,<span class="st">&quot;red&quot;</span>,label<span class="op">=</span><span class="st">&quot;Root&quot;</span>)
ax.legend(loc<span class="op">=</span><span class="st">&quot;best&quot;</span>, bbox_to_anchor<span class="op">=</span>(<span class="dv">1</span>,<span class="dv">1</span>))
plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_43_0.png" width="100%" style="display: block; margin: auto;" /></p>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 找到两个函数的交点</span>
<span class="co">## 定义一个函数来简化求交点的过程</span>
<span class="kw">def</span> findIntersection(func1,func2,x0):
    <span class="cf">return</span> fsolve(<span class="kw">lambda</span> x:func1(x)<span class="op">-</span>func2(x),x0)

<span class="co">## 定义两个函数，准备求它们的交点</span>
funky<span class="op">=</span><span class="kw">lambda</span> x:np.cos(x<span class="op">/</span><span class="dv">5</span>)<span class="op">*</span>np.sin(x<span class="op">/</span><span class="dv">2</span>)
line<span class="op">=</span><span class="kw">lambda</span> x:<span class="fl">0.01</span><span class="op">*</span>x<span class="fl">-0.5</span>

<span class="co">## 设置函数的定义域，求两个函数的交点</span>
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">45</span>,<span class="dv">10000</span>)
result<span class="op">=</span>findIntersection(funky,line,[<span class="dv">15</span>,<span class="dv">20</span>,<span class="dv">30</span>,<span class="dv">35</span>,<span class="dv">40</span>,<span class="dv">45</span>])

<span class="co">## 打印交点的坐标</span>
<span class="bu">print</span>(result,line(result))</code></pre></div>
<pre><code>[ 13.40773078  18.11366128  31.78330863  37.0799992   39.84837786
  43.8258775 ] [-0.36592269 -0.31886339 -0.18216691 -0.12920001 -0.10151622 -0.06174122]</code></pre>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig <span class="op">=</span> plt.figure()
ax<span class="op">=</span>fig.add_subplot(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>)
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">45</span>,<span class="dv">10000</span>)
ax.plot(x,funky(x),<span class="st">&quot;blue&quot;</span>,label<span class="op">=</span><span class="st">&quot;Funky&quot;</span>)
ax.plot(x,line(x),<span class="st">&quot;green&quot;</span>,label<span class="op">=</span><span class="st">&quot;Line&quot;</span>)
ax.scatter(result,line(result),<span class="dv">25</span>,<span class="st">&quot;red&quot;</span>)
ax.legend(loc<span class="op">=</span><span class="st">&quot;best&quot;</span>, bbox_to_anchor<span class="op">=</span>(<span class="dv">1</span>,<span class="dv">1</span>))
plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_45_0.png" width="100%" style="display: block; margin: auto;" /></p>
</div>
</div>
<div id="section-6.2.2" class="section level3">
<h3><span class="header-section-number">6.2.2</span> 插值</h3>
<ul>
<li>插值法在离散数据的基础上补插连续函数，使得这条连续曲线通过全部给定的离散数据点。</li>
<li>插值是离散函数逼近的重要方法，利用它可通过函数在有限个点处的取值状况，估算出函数在其他点处的近似值。</li>
<li>常用来填充图像变换时像素之间的空隙。</li>
<li>计算插值有两种基本方法：
<ul>
<li>用一个函数对整个数据集进行拟合</li>
<li>对数据集不同的部分用几个不同函数拟合，各函数的连接点都是光滑的</li>
</ul></li>
<li>第二种方法称为样条插值，当数据的函数形式复杂的时候，样条插值是非常强大的工具</li>
</ul>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">from</span> scipy.interpolate <span class="im">import</span> interp1d</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 创建离散数据集</span>
x<span class="op">=</span>np.linspace(<span class="dv">0</span>,<span class="dv">10</span><span class="op">*</span>np.pi,<span class="dv">20</span>)
y<span class="op">=</span>np.cos(x)

<span class="co">## 分别用线性函数和二次函数，对数据进行插值</span>
fl<span class="op">=</span>interp1d(x,y,kind<span class="op">=</span><span class="st">&quot;linear&quot;</span>)
fq<span class="op">=</span>interp1d(x,y,kind<span class="op">=</span><span class="st">&quot;quadratic&quot;</span>)

<span class="co">## 得到两个连续函数上的点</span>
xint<span class="op">=</span>np.linspace(x.<span class="bu">min</span>(),x.<span class="bu">max</span>(),<span class="dv">1000</span>)
yintl<span class="op">=</span>fl(xint)
yintq<span class="op">=</span>fq(xint)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig <span class="op">=</span> plt.figure()
ax<span class="op">=</span>fig.add_subplot(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>)
ax.plot(x,y,<span class="st">&quot;ro&quot;</span>,xint,yintl,<span class="st">&quot;g-&quot;</span>,xint,yintq,<span class="st">&quot;b-&quot;</span>)
plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_49_0.png" width="100%" style="display: block; margin: auto;" /></p>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">from</span> scipy.interpolate <span class="im">import</span> UnivariateSpline</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co">## 对有噪声的函数进行插值</span>
<span class="co">## 创建数据集，加入人工噪声</span>
sample<span class="op">=</span><span class="dv">30</span>
x<span class="op">=</span>np.linspace(<span class="dv">1</span>,<span class="dv">10</span><span class="op">*</span>np.pi,sample)
y<span class="op">=</span>np.cos(x)<span class="op">+</span>np.log10(x)<span class="op">+</span>np.random.randn(sample)<span class="op">/</span><span class="dv">10</span>

<span class="co">## 对数据进行插值，参数s是光滑因子，若s=0，插值会经过所有点不考虑噪声，若s=1，则考虑噪声</span>
f<span class="op">=</span>UnivariateSpline(x,y,s<span class="op">=</span><span class="dv">1</span>)

<span class="co">## 得到插值函数上的点</span>
xint<span class="op">=</span>np.linspace(x.<span class="bu">min</span>(),x.<span class="bu">max</span>(),<span class="dv">1000</span>)
yint<span class="op">=</span>f(xint)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">fig <span class="op">=</span> plt.figure()
ax<span class="op">=</span>fig.add_subplot(<span class="dv">1</span>,<span class="dv">1</span>,<span class="dv">1</span>)
x1000<span class="op">=</span>np.linspace(<span class="dv">1</span>,<span class="dv">10</span><span class="op">*</span>np.pi,<span class="dv">1000</span>)
y1000<span class="op">=</span>np.cos(x1000)<span class="op">+</span>np.log10(x1000)
ax.plot(x,y,<span class="st">&quot;ro&quot;</span>,x1000,y1000,<span class="st">&quot;b-&quot;</span>,xint,yint,<span class="st">&quot;g-&quot;</span>)
plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_52_0.png" width="100%" style="display: block; margin: auto;" /></p>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="im">from</span> scipy.interpolate <span class="im">import</span> griddata</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python"><span class="co"># 创建一个1000*1000像素的图片，在图片上随机选1000个点，看插值函数如何能根据这1000个点重构图片</span>
<span class="co">## 创建一个函数</span>
ripple<span class="op">=</span><span class="kw">lambda</span> x,y:np.sqrt(x<span class="op">**</span><span class="dv">2</span><span class="op">+</span>y<span class="op">**</span><span class="dv">2</span>)<span class="op">+</span>np.sin(x<span class="op">**</span><span class="dv">2</span><span class="op">+</span>y<span class="op">**</span><span class="dv">2</span>)
<span class="co">## 生成网格数据，复数1000j表示在0到5之间生成1000个点，包含0和5</span>
grid_x, grid_y <span class="op">=</span> np.mgrid[<span class="dv">0</span>:<span class="dv">5</span>:1000j, <span class="dv">0</span>:<span class="dv">5</span>:1000j]
<span class="co">## 随机生成插值函数可见的1000个点的抽样</span>
xy <span class="op">=</span> np.random.rand(<span class="dv">1000</span>, <span class="dv">2</span>)
sample <span class="op">=</span> ripple(xy[:,<span class="dv">0</span>] <span class="op">*</span> <span class="dv">5</span> , xy[:,<span class="dv">1</span>] <span class="op">*</span> <span class="dv">5</span>)
<span class="co">## 用三次函数方法生成抽样数据的插值</span>
grid_z0 <span class="op">=</span> griddata(xy <span class="op">*</span> <span class="dv">5</span>, sample, (grid_x, grid_y), method<span class="op">=</span><span class="st">&#39;cubic&#39;</span>)
<span class="co">## 用线性方法生成抽样数据的插值</span>
grid_z1 <span class="op">=</span> griddata(xy <span class="op">*</span> <span class="dv">5</span>, sample, (grid_x, grid_y), method<span class="op">=</span><span class="st">&#39;linear&#39;</span>)
<span class="co">## 用Nearest方法生成抽样数据的插值</span>
grid_z2 <span class="op">=</span> griddata(xy <span class="op">*</span> <span class="dv">5</span>, sample, (grid_x, grid_y), method<span class="op">=</span><span class="st">&#39;nearest&#39;</span>)</code></pre></div>
<div class="sourceCode"><pre class="sourceCode python"><code class="sourceCode python">plt.subplot(<span class="dv">221</span>)
plt.title(<span class="st">&#39;Original&#39;</span>)
plt.imshow(ripple(grid_x, grid_y).T,extent<span class="op">=</span>(<span class="dv">0</span>,<span class="dv">5</span>,<span class="dv">0</span>,<span class="dv">5</span>))
plt.plot(xy[:,<span class="dv">0</span>]<span class="op">*</span><span class="dv">5</span>, xy[:,<span class="dv">1</span>]<span class="op">*</span><span class="dv">5</span>, <span class="st">&#39;b.&#39;</span>,ms<span class="op">=</span><span class="dv">3</span>)
plt.subplot(<span class="dv">222</span>)
plt.title(<span class="st">&#39;Cubic&#39;</span>)
plt.imshow(grid_z0.T,extent<span class="op">=</span>(<span class="dv">0</span>,<span class="dv">5</span>,<span class="dv">0</span>,<span class="dv">5</span>))
plt.subplot(<span class="dv">223</span>)
plt.title(<span class="st">&#39;Linear&#39;</span>)
plt.imshow(grid_z1.T,extent<span class="op">=</span>(<span class="dv">0</span>,<span class="dv">5</span>,<span class="dv">0</span>,<span class="dv">5</span>))
plt.subplot(<span class="dv">224</span>)
plt.title(<span class="st">&#39;Nearest&#39;</span>)
plt.imshow(grid_z2.T,extent<span class="op">=</span>(<span class="dv">0</span>,<span class="dv">5</span>,<span class="dv">0</span>,<span class="dv">5</span>))
plt.show()</code></pre></div>
<p><img src="08_Python_pythonic_numpy_scipy_files/08_Python_pythonic_numpy_scipy_55_0.png" width="100%" style="display: block; margin: auto;" /></p>

</div>
</div>
</div>
            </section>

          </div>
        </div>
      </div>
<a href="py3-pandas-ct.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="Py3-test.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook-2.6.7/js/app.min.js"></script>
<script src="libs/gitbook-2.6.7/js/lunr.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-search.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-sharing.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook-2.6.7/js/plugin-bookdown.js"></script>
<script src="libs/gitbook-2.6.7/js/jquery.highlight.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": false,
"facebook": false,
"twitter": false,
"google": false,
"weibo": false,
"instapper": false,
"vk": false,
"all": ["facebook", "google", "twitter", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": null,
"text": null
},
"download": ["Py3_course.pdf"],
"toc": {
"collapse": "subsection"
}
});
});
</script>

</body>

</html>
